<?php

/**
 * Content form.
 *
 * @package    ##PROJECT_NAME##
 * @subpackage form
 * @author     ##AUTHOR_NAME##
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class ContentForm extends BaseContentForm
{
    public function configure()
    {
        $this->widgetSchema['link_content_asset_list'] = new inputAssetMultiple( );
        $this->widgetSchema->setLabel('link_content_asset_list','Assets');

        unset($this['link_content_asset_list']);
        unset($this['created_at']);
        unset($this['created_by']);
        unset($this['updated_at']);
        unset($this['type']);

        unset( $this['user_id'] , $this['hits'] );

        $filters = sfContext::getInstance()->getUser()->getAttribute('content.filters',array(),'admin_module');
        if( !empty($filters['category_id']) ) {
            //var_dump($filters['category_id']);exit;
            $this->setDefault( 'category_id' , $filters['category_id'] );
            $this->widgetSchema['category_id'] = new sfWidgetFormInputHidden();
        }

    }

    protected function doSave($con = null){

        if(!sfContext::getInstance()->getUser()->isAuthenticated()){

            throw new Exception('you cannot add content if you are not logged in');
        }

        $this->getObject()->setUserId( sfContext::getInstance()->getUser()->getGuardUser()->getId() );
        parent::doSave($con);
    }
}
